<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div>
        <a href="#/index">首页</a>
        <a href="#/add">不是首页</a>
    </div>
    <div id="con">

    </div>
    <script>
        window.addEventListener('hashchange', () => {
            console.log('哈希值变化了', window.location);
            if (window.location.hash === '#/index') {
                document.getElementById('con').innerHTML = `
                我是一个主页
                `
            } else if (window.location.hash === '#/add') {
                document.getElementById('con').innerHTML = `
                我不是一个主页
                `
            }

        })
    </script>
</body>

</html>